﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BLL;

namespace Web.Shalo.BanPMS1.Admin
{
    public partial class TTNhanVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["manv"] == null || Session["matkhau"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    MultiView1.ActiveViewIndex = 0;
                    HienThiNV();
                }
            }
        }

        public void HienThiNV()
        {
            NhanVienController obj = new NhanVienController();
            DataTable NV = obj.bllHienThiNV(Session["manv"].ToString());
            txtTennv.Text = NV.Rows[0]["TenNV"].ToString();
            txtDiachi.Text = NV.Rows[0]["DiaChi"].ToString();
            txtEmail.Text = NV.Rows[0]["Email"].ToString();
            txtSdt.Text = NV.Rows[0]["Sdt"].ToString();
            string gioitinh = NV.Rows[0]["GioiTinh"].ToString();
            if (gioitinh == "Nam")
                ddGioiTinh.Text = "0";
            else
                ddGioiTinh.Text = "1";
            string ngaysinh = NV.Rows[0]["NgaySinh"].ToString();
            if (ngaysinh.Length > 0)
            {
                ddNgay.Text = ngaysinh.Substring(0, ngaysinh.Length - 8);
                ddThang.Text = ngaysinh.Substring(3, 2);
                txtNam.Text = ngaysinh.Substring(6, 4);
            }
        }

        protected void btnSuaMK_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }

        protected void btnThoat_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanTri.aspx");
        }

        protected void btnThoat2_Click(object sender, EventArgs e)
        {
            Response.Redirect("TTNhanVien.aspx");
        }

        protected void btnLuuMH_Click(object sender, EventArgs e)
        {
            NhanVienController obj = new NhanVienController();
            bool res = obj.bllTDMatKhau(Session["manv"].ToString(),txtMatkhaucu.Text, txtNhaplaimatkhau.Text);
            ThongBao(res);
        }

        public void ThongBao(bool res)
        {
            if (res)
            {
                Response.Redirect("TTNhanVien.aspx");
            }
            else
            {
                Page.RegisterClientScriptBlock("mes", "<script language='javascript'>alert('Thất Bại')</script>");
            }
        }

        protected void btnSuaNV_Click(object sender, EventArgs e)
        {
            bool res = false;
            NhanVienController obj = new NhanVienController();
            string ngaysinh = ddThang.SelectedItem.ToString() + "/" + ddNgay.SelectedItem.ToString() + "/" + txtNam.Text;
            string matkhau = ddNgay.SelectedItem.ToString() + ddThang.SelectedItem.ToString() + txtNam.Text;
            int gioitinh = Convert.ToInt16(ddGioiTinh.SelectedValue.ToString());
            res = obj.bllSuaNV(txtTennv.Text, ngaysinh, gioitinh, txtDiachi.Text, txtSdt.Text, txtEmail.Text, Session["manv"].ToString());
            ThongBao(res);
        }
    }
}